﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

using CarFrameWork.Common;

namespace CarFrameWork.UI.Common
{
    public partial class frmclassid : Form
    {
        bool pd = false;
        string Str= "";
        string qzorhq = "";
        public frmclassid()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != ""&&textBox1.Text.Length==10&&textBox2.Text!=""&&textBox2.Text.Length==10)
            {
                MessageBox.Show("输入正确！");
                if (Str != ""&&qzorhq!="")
                {
                    string sql = "select count(*) from "+Str+" where "+qzorhq+"='" + textBox1.Text + "'";
                    MessageBox.Show(sql,"显示sql语句");
                    try
                    {
                        //string MyConn = "Data Source=DISCOVER;Initial Catalog=cheqiaoxuanjia;Trusted_Connection=SSPI";
                        string MyConn = SqlWork.dbconn();
                        SqlConnection MyConnection = new SqlConnection(MyConn);
                        MyConnection.Open();
                        SqlCommand MyCommand = new SqlCommand(sql, MyConnection);
                        int state = Convert.ToInt32(MyCommand.ExecuteScalar());
                        if (state == 0 || state > 1)
                        {
                            MessageBox.Show("此型号不存在！");
                            pd = true;
                            this.Close();
                        }
                        else 
                        {
                            MessageBox.Show("此型号存在！");
                            pd=false;
                            textBox1.Text = "";
                        }
                        MyConnection.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message,"错误！");
                    }
                }
            }
            else
            {
                MessageBox.Show("型号类型或适用车型输入错误！","ERROR!");
                textBox1.Text = "";
            }

           // String Str = textBox1.Text;
           // MessageBox.Show(Str.Substring(6,Str.IndexOf("0")).Trim());
        }

        public string PartType()//返回输入的零件型号
        {
            if (pd == true)
                return this.textBox1.Text;
            else
                return "";
        }
        public string CarType()
        {
            if (pd == true)
                return this.textBox2.Text;
            else
                return "";
        }

        public void input(string sql_command,string qorh)//传入查询的查询表名称
        {
            Str = sql_command;
            qzorhq = qorh;
        }

        private void frmclassid_Load(object sender, EventArgs e)
        {
            //frmskin.SkinWindowSet(label1.Handle, 221);
            //frmskin.SkinWindowSet(label2.Handle, 221);
        }
    }
}